package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.YaoluBankFlow;
import cn.stylefeng.guns.sys.modular.system.mapper.YaoluBankFlowMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.YaoluBankFlowParam;
import cn.stylefeng.guns.sys.modular.system.model.result.YaoluBankFlowResult;
import  cn.stylefeng.guns.sys.modular.system.service.YaoluBankFlowService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liuy
 * @since 2022-06-20
 */
@Service
public class YaoluBankFlowServiceImpl extends ServiceImpl<YaoluBankFlowMapper, YaoluBankFlow> implements YaoluBankFlowService {

    @Override
    public void add(YaoluBankFlowParam param){
        YaoluBankFlow entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(YaoluBankFlowParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(YaoluBankFlowParam param){
        YaoluBankFlow oldEntity = getOldEntity(param);
        YaoluBankFlow newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public YaoluBankFlowResult findBySpec(YaoluBankFlowParam param){
        return null;
    }

    @Override
    public List<YaoluBankFlowResult> findListBySpec(YaoluBankFlowParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(YaoluBankFlowParam param){
        //拼接查询条件
        String beginTime = "";
        String endTime = "";
        if (ToolUtil.isNotEmpty(param.getTimeLimit())) {
            String[] split = param.getTimeLimit().split(" - ");
            beginTime = split[0].replace("-","");
            endTime = split[1].replace("-","");;
            param.setBeginTime(beginTime);
            param.setEndTime(endTime);
        }
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public void insertYaoluBankFlow(List<YaoluBankFlow> list) {
        baseMapper.insertYaoluBankFlow(list);
    }

    @Override
    public List<YaoluBankFlowResult> bankListByDm(YaoluBankFlowParam param) {
        return baseMapper.bankListByDm(param);
    }

    @Override
    public List<YaoluBankFlowResult> bankZcListByDm(YaoluBankFlowParam param) {
        return baseMapper.bankZcListByDm(param);
    }

    @Override
    public List<YaoluBankFlowResult> dmList() {
        return null;
    }

    private Serializable getKey(YaoluBankFlowParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private YaoluBankFlow getOldEntity(YaoluBankFlowParam param) {
        return this.getById(getKey(param));
    }

    private YaoluBankFlow getEntity(YaoluBankFlowParam param) {
        YaoluBankFlow entity = new YaoluBankFlow();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
